<?
require_once('functions.php');

function GetCustomers()
{
        $conn = GetConnection();
        return $conn->query('SELECT * FROM Customers');
}
function GetCustomer($id)
{
        $conn = GetConnection();
        $sql = "SELECT * FROM Customers WHERE id=$id";
        $results = $conn->query($sql);
        //echo $sql;
        $row = $results->fetch_assoc();
        $conn->close();
        return $row;
}
function SaveCustomer($row)
{
        $conn = GetConnection();
        $row2 = EscapeRow($row, $conn);
        $sql =  "UPDATE Customers "
                .       "Set FirstName='$row2[FirstName]', LastName='$row2[LastName]', created_at='$row2[created_at]', id='$row2[Keyword_id]' "
                .       "WHERE id=$row2[id] ";
        $results = $conn->query($sql);
        //echo $sql;
        $error = $conn->error;
        $conn->close();
        
        return $error == '' ? true : array('SQL Error' => $error);
}
function Delete($row)
{
	$conn = GetConnection();
	$row2 = EscapeRow($row, $conn);
	$sql = "DELETE FROM Customers "
		. 	"WHERE id=$row2[id] ";
	$results = $conn->query($sql);
    //echo $sql;
    $error = $conn->error;
    $conn->close();
    return $error == '' ? true : array('SQL Error' => $error);
}
function DeleteCustomer($value){
    
    $conn = GetConnection();
    $sql = "DELETE FROM Customer WHERE id='$row[id]' ";
    $result1 = $conn->query($sql);
    $conn->close();
                
}
function EscapeRow($row, $conn)
{
        $arr = array();
        foreach ($row as $key => $value) {
                $arr[$key] = $conn->real_escape_string($value);
        }
        return $arr;    
}